package com.tul.exercise.base.thread.exercise;

import java.util.ArrayList;
import java.util.List;

class Fibonacci implements Runnable {
    private int n;

    public Fibonacci(int n) {
        this.n = n;
    }

    /**
     * 根据n产生斐波那契数列的第n个数
     *
     * @param n n
     * @return 第n个数
     */
    private int fibonacci(int n) {
        if (n == 1 || n == 2) {
            return 1;
        } else {
            return fibonacci(n - 1) + fibonacci(n - 2);
        }
    }

    @Override
    public void run() {
        List<Integer> numbers = new ArrayList<>();

        for (int i = 1; i <= n; i++) {
            numbers.add(fibonacci(i));
        }

        System.out.println(numbers);

    }
}

public class Eg2 {
    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            (new Thread(new Fibonacci((i + 1) % 10))).start();
        }
    }
}
